package com.example.manualManagement.controller;

import com.example.manualManagement.entity.Manage;
import com.example.manualManagement.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ManageCtrl {


    @Autowired
    private ManageService manageService;


    @RequestMapping("/manage/register")
    public String insert(Integer userId, String userName, String userPassword){
        PasswordEncoder passwordencoder = new BCryptPasswordEncoder();
        String encodedPassword = passwordencoder.encode(userPassword);
        Manage manage = new Manage(userId, userName, encodedPassword);
        int result = manageService.insertUser(manage);
        if(result >= 1){
            return "注册成功";
        }else{
            return "注册失败";
        }
    }

    @RequestMapping("/manage/login")
    public Manage findByName(String userName){
        return manageService.findByName(userName);
    }
}
